package com.zg.api.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.api.domain.convert.ApiServiceConvert;
import com.zg.api.domain.req.ApiServiceAddReq;
import com.zg.api.domain.req.ApiServiceEditReq;
import com.zg.api.domain.req.ApiServicePageReq;
import com.zg.api.domain.vo.ApiServiceVo;
import com.zg.api.service.ApiServiceService;
import com.zg.common.core.R;
import com.zg.common.core.dao.apis.entity.ApiService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/16 20:23
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/service")
@Slf4j
@Api(tags = "服务信息")
public class ApiServiceController {

    private final ApiServiceService serviceService;

    private final ApiServiceConvert apiServiceConvert;

    @PostMapping("/page")
    public R page(@RequestBody ApiServicePageReq pageReq) {
        Page<ApiServiceVo> page = serviceService.pageService(pageReq, ApiServiceVo.class);

        return R.success(apiServiceConvert.toEntityPage(page));
    }


    @PostMapping("/add")
    public R add(@Validated @RequestBody ApiServiceAddReq addReq) {
        serviceService.add(addReq);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@Validated @RequestBody ApiServiceEditReq editReq) {
        serviceService.edit(editReq);
        return R.success();
    }

    @PostMapping("/remove")
    public R remove(@RequestBody  List<Long> ids) {
        serviceService.remove(ids);
        return R.success();
    }

    @GetMapping("/list")
    public R<List<ApiServiceVo>> list() {
        List<ApiService> vList=serviceService.list();
        return R.success(apiServiceConvert.toVoList(vList));
    }
}
